package com.mycompany.app.hr.eleave.webapp.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.mycompany.app.hr.common.pagination.Page;
import com.mycompany.app.hr.common.pagination.displaytag.DisplayTagPaginationHelper;
import com.mycompany.app.hr.eleave.model.LeaveType;
import com.mycompany.app.hr.eleave.service.impl.LeaveTypeServiceImpl;
import com.mycompany.app.util.SpringUtils;
import com.mycompany.app.webapp.action.BaseAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("serial")
public class LeaveTypeAction extends BaseAction {

    private List<LeaveType> allLeaveTypes;

    private Page<LeaveType> page = new Page<LeaveType>(5, true);

    public Page<LeaveType> getPage() {

        return page;
    }

    public void setPage(Page<LeaveType> page) {

        this.page = page;
    }

    private LeaveTypeServiceImpl leaveTypeService;

    public LeaveTypeServiceImpl getLeaveTypeService() {

        return leaveTypeService;
    }

    public void setLeaveTypeService(LeaveTypeServiceImpl leaveTypeService) {

        this.leaveTypeService = leaveTypeService;
    }

    public List<LeaveType> getAllLeaveTypes() {

        return allLeaveTypes;
    }

    public void setAllLeaveTypes(List<LeaveType> allLeaveTypes) {

        this.allLeaveTypes = allLeaveTypes;
    }

    public String list() {

        HttpServletRequest request = (HttpServletRequest) ActionContext
                .getContext().get(ServletActionContext.HTTP_REQUEST);

        page.setPageNo(DisplayTagPaginationHelper.getCurrentPageNum(request,
                null));
        page.setOrderBy(DisplayTagPaginationHelper.getSortingColumnName(
                request, null));
        page.setAsc(DisplayTagPaginationHelper.isSortingAsc(request, null));

        SpringUtils.bindSession();
        System.out.println(page);
        allLeaveTypes = leaveTypeService.getAllLeaveTypes(page);
        SpringUtils.unbindSession();

        return Action.SUCCESS;
    }

}
